﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace dzs.Web.supply
{
    public partial class AddSupplyDate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["supplyPlanId"] != null)
                {
                    string supplyId = Session["supplyPlanId"].ToString();
                    Bind(supplyId);
                }
            }
        }

        private void Bind(string supplyPlanId)
        {
            DataSet ds = new Maticsoft.BLL.supplyPlan().GetList(" supplyPlanId=" + supplyPlanId);

            this.lbl_material.Text = ds.Tables[0].Rows[0]["material"].ToString();
            this.lbl_num.Text = ds.Tables[0].Rows[0]["num"].ToString();
            this.lbl_proid.Text = ds.Tables[0].Rows[0]["proid"].ToString();
            this.lbl_projectname.Text = ds.Tables[0].Rows[0]["projectName"].ToString();
            this.lbl_slink.Text = ds.Tables[0].Rows[0]["slink"].ToString();
            this.lbl_sname.Text = ds.Tables[0].Rows[0]["sname"].ToString();
            this.lbl_unit.Text = ds.Tables[0].Rows[0]["unit"].ToString();
            if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["supplyDate"].ToString()))
            {
                this.txt_supplyDate.Text = DateTime.Parse(ds.Tables[0].Rows[0]["supplyDate"].ToString()).ToShortDateString();
            }
            this.lbl_semail.Text = ds.Tables[0].Rows[0]["semail"].ToString();
            this.lbl_sfax.Text = ds.Tables[0].Rows[0]["sfax"].ToString();
            this.lbl_sphone.Text = ds.Tables[0].Rows[0]["sphone"].ToString();
            this.lbl_psemail.Text = ds.Tables[0].Rows[0]["psemail"].ToString();
            this.lbl_psfax.Text = ds.Tables[0].Rows[0]["psfax"].ToString();
            this.lbl_pslink.Text = ds.Tables[0].Rows[0]["pslink"].ToString();
            this.lbl_psphone.Text = ds.Tables[0].Rows[0]["psphone"].ToString();
            
        }

        protected void btn_confirm_Click(object sender, EventArgs e)
        {
            string supplyDate = txt_supplyDate.Text;//供货年月
            int supplyPlanId = 0;

            if (Session["supplyPlanId"] != null)
            {
                supplyPlanId = int.Parse(Session["supplyPlanId"].ToString());
                if (!string.IsNullOrEmpty(supplyDate))
                {
                    Maticsoft.BLL.supplyPlan sm = new Maticsoft.BLL.supplyPlan();
                    Maticsoft.Model.supplyPlan s = sm.GetModel(supplyPlanId);

                    s.supplyDateStatus = "已确认";
                    s.supplyDateStatusDate = DateTime.Now;
                    s.supplyDate = DateTime.Parse(supplyDate);

                    if (sm.Update(s))
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.returnValue=true;parent.close();</script>");
                    }


                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "请确认日期！");
                }
            }
        }
    }
}